<template>
  <form class="form-validate" @submit.prevent="onSubmit">
    <slot></slot>
  </form>
</template>

<script>
export default {
  methods: {
    onSubmit() {
      let aValidInput = []
      let aErrorInput = []
      this.$children.forEach(item => {
        if (/validate/.test(item.$el.className)) {
          aValidInput.push(item)
        }
      })
      for (let i = 0; i < aValidInput.length; i++) {
        if (aValidInput[i]._validateInput()) {
          aErrorInput.push(aValidInput[i])
          return
        }
      }
      this.$emit('on-validate')
    }
  }
}
</script>
